package com.qf.fronted.dao.selectaddress.impl;

import com.qf.fronted.dao.selectaddress.IProvinceDao;
import com.qf.fronted.domain.Province;
import com.qf.utils.DruidUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class ProvinceDaoImpl implements IProvinceDao {

    private QueryRunner queryRunner = new QueryRunner(DruidUtils.getDataSource());

    //查询所有省份
    @Override
    public List<Province> selectAllProvince() {
        String sql = "SELECT id,name FROM province";
        try {
            return queryRunner.query(sql, new BeanListHandler<>(Province.class));
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return new ArrayList<>(0);
    }

}
